package com.markerhub.common.lang;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result implements Serializable {

    private int code;  // 200表示正常，非200表示异常
    private String msg;
    private Object data;

    public static Result succ(int code, String msg, Object data) {
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);

        return r;
    }

    // 操作成功的返回
    public static Result succ(Object data) {

        return Result.succ(200, "操作成功", data);
    }

    /**
     * 操作失败
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public static Result fail(int code, String msg, Object data) {
        Result r = new Result();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(data);

        return r;
    }

    public static Result fail(String msg, Object data) {
        Result r = new Result();
        r.setCode(400);
        r.setMsg(msg);
        r.setData(data);

        return r;
    }

    public static Result fail(String msg) {
        Result r = new Result();
        r.setCode(400);
        r.setMsg(msg);
        r.setData(null);

        return r;
    }
}
